How to chown Recursively on Linux? – Its Linux FOSS |
您所在的位置:网站首页 › groups linux › How to chown Recursively on Linux? – Its Linux FOSS |
In Linux, the “chown” command allows users to change the ownership (including group) of the specified file/directory. The “chown” command supports recursive operations, by which the owner of all the files/subdirectories can be changed. This guide illustrates how the chown command changes the ownership recursively in Linux. How To chown Recursively on Linux? Change the User’s Ownership Only Change the Group Recursively Change the Owner and Group Recursively How To Chown Recursively with find Command on Linux? How to chown Recursively on Linux?The “chown” command offers the “-R” flag to change the ownership of files or subdirectories in the current working directory. The syntax of the chown command for recursive operations is Syntax: $ chown -R user #To change the Owner Only $ chown -R :group #To Chnage the Group Only $ chown -R user:group #To Chnage the Owner and GroupHere, the “user” and the “group” are the new user and group names that will be replaced with the current one. Example 1: Change the User’s Ownership Only How to Install Packages in UbuntuPlease enable JavaScript The example shows the “Sample” directory having a username and group name “itslinuxfoss” with the following files and subdirectories: $ ls -l SampleTo change its ownership, execute the chown command recursively followed by “-R” flag in the following way: $ sudo chown -R anna SampleThe output confirms the ownership of “Sample” directory from “itslinuxfoss” to “anna”. Example 2: Change the Group RecursivelyTo change the group of the directory recursively, use the chown command will “-R” and specify the current and the new group name (i.e., anna:johnson): $ sudo chown -R anna:johnson SampleTo verify, use the “ls -l” command on the directory as follows: $ ls -l SampleThe “Sample” directory and all of its content have now been associated with the “johnson” group. Example 3: Change the Owner and Group RecursivelyTo change both the owner and group together using the “chown recursively” command, specify both names in one command like this: In this case, the “Extra” dir directory and its files or subdirectories have a username and group name “johnson”: $ ls -l ExtraChange the “Extra” directory owner and group name recursively using this command: $ sudo chown -R johnson:milton ExtraThe username “johnson” and group name “milton” has been assigned to the “Extra” directory recursively. Example 4: Find Files and Change Their OwnershipApart from directories, the user can also change the ownership of multiple files using the “chown recursively” combination of the “find” command. For this purpose, use the following command: $ sudo find . -type f -name "*.txt" -exec chown anna:johnson {} \;The command holds following parameters. find: Represents the “find” command line tool that finds the files. type f: Shows the “type” command that is beneficial to check the command type. In this syntax, the “f” find files. name: Displays the file extension “.txt” exec: execute the chown commandThe command is successfully executed. To verify the results, use the “find” command again in this way: $ find ~/ -group johnson -user annaThe above output verifies that all the “.txt” files have owner name “anna” and the group name “johnson”. ConclusionIn Linux, the “chown recursively” changes the ownership and the group name of the directories and all the subdirectories/files inside it. The “-R(recursively)” flag is used for this operation. It also allows the users to recursively change the ownership of all files with the combination of the “find” command. This post has described all possible aspects of chown recursively on Linux. Anna |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |